/* 
 * File:   main.c
 * Author: bhavya
 *
 * Created on October 5, 2011, 1:18 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>

/*
 * 
 */
typedef struct {
    int lowerOffset;
    int upperOffset;
    int processorNumber;
    FILE *fp;
} patternPartitioning;

int main(int argc, char** argv) {


    char pattern[256];
    FILE *fp;
    // char* filename = "/home/bhavya/Desktop/10_seqs_200_300_bp.fasta";
    char filename[256];
    int n = 0;
    int d = 0;
    //number of processors
    int k , i = 0, lower_limit, upper_limit;
    patternPartitioning partition[k];

    printf(" enter the location of the fasta file");
    scanf("%s", filename);
    fp = fopen(filename, "r");
    if (fp != '\0') {
        fseek(fp, 0L, SEEK_END);
        n = ftell(fp);
        fseek(fp, 0L, SEEK_SET);
        printf(" value of text length is %d\n", n);
    }
    printf("enter the value of the pattern\n");
    scanf("%s", pattern);
    int m = strlen(pattern);
    printf("pattern length is %d \n", m);
    printf("enter the number of processors\n");
    scanf("%d", &k);
    d = (n - m + 1) / k;
    printf(" the value of d is%d \n",d);
    for (i = 0; i <= k - 2; i++) {
        lower_limit = round(i * d);
        upper_limit = round((i + 1) * d) + m - 1;
        partition->lowerOffset=lower_limit;
        partition->upperOffset=upper_limit;
        partition->processorNumber=i;
        partition->fp=fp;
        // k-2 times calculate the limits like this
        printf(" the lower limit is %d and upper limit is%d\n", partition->lowerOffset, partition->upperOffset);
    }
    // for the last processor calculate the index here
    lower_limit = round((k - 1) * d);
    upper_limit = n;
    partition->lowerOffset=lower_limit;
    partition->upperOffset=n;
    partition->processorNumber=k;
    partition->fp=fp;
    printf(" the lower limit is %d and upper limit is %d\n", partition->lowerOffset, partition->upperOffset);
    return (EXIT_SUCCESS);
}

